package beans;

import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;

import manager.SessionManager;

@ManagedBean(name="loginBean")
@ViewScoped
public class LoginBean implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private String theme;
	
	private String user;
	private String pass;

	public LoginBean() {
		super();
//		Object themeObject = FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("theme");
//		if(themeObject != null){
//			theme = themeObject.toString();
//		}
//		else{
//			theme = "default";
//		}
//		user = "A07111";
	}
	
	
	public LoginBean(String user, String pass) {
		super();
		this.user = user;
		this.pass = pass;
	}
	
	public String login(){

		HttpServletRequest httpServletRequest = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();  
		String loginUser = httpServletRequest.getRemoteUser().substring(7);
		
		FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("loginUser", loginUser);
		
		if(user.equals(""))
			user = "A07111";
		FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("user", user);
		FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("pass", pass);
		return "caller.jsf?faces-redirect=true";
	}
	public void saveSize(){
		
	}
	public String getUser() {
		return user;
	}
	public void setUser(String user) {
		this.user = user;
	}
	public String getPass() {
		return pass;
	}
	public void setPass(String pass) {
		this.pass = pass;
	}
	public String getTheme() {
		return theme;
	}
	public void setTheme(String theme) {
		this.theme = theme;
	}
	public String getWidth(){
		Object widthObj = FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("width");
		if(widthObj == null)
			return "1900";
		return widthObj.toString();
	}
	public void setWidth(String width){
		FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("width", width);
	}
	public String getHeight(){
		Object heightObj = FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("height");
		if(heightObj == null)
			return "1200";
		return heightObj.toString();
	}
	public void setHeight(String height){
		FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("height", height);
	}

	
}
